/**
 * 
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 *   
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 * 
 */
package org.jiopi.ibean.kernel.context.classloader;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import java.util.ArrayList;

import org.jiopi.framework.FrameworkInitializer;
import org.jiopi.framework.core.loader.CentralConsoleKernelLoaderFactory;
import org.jiopi.ibean.kernel.IBeanCentralConsoleKernel;
import org.jiopi.ibean.kernel.context.ContextCentralConsoleKernel;
import org.jiopi.ibean.kernel.util.ObjectAccessor;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

public class CommonLibClassLoaderManagerTestCase {
	@BeforeClass public static void init(){
		FrameworkInitializer.initialize();
	}
	
	/**
	 * only run in Debug mode
	 * @throws ClassNotFoundException
	 */
	//
	@Ignore @Test public void CommonLibClassLoader_Right(){
		IBeanCentralConsoleKernel icck = (IBeanCentralConsoleKernel)CentralConsoleKernelLoaderFactory.loadCentralConsoleKernel();
		ContextCentralConsoleKernel ccck = ObjectAccessor.Accessible.method(icck, "getContextCentralConsoleKernel", ContextCentralConsoleKernel.class);
		
		CommonLibClassLoaderManager clclm = new CommonLibClassLoaderManager(ccck);
		
		CommonLibClassLoader clcl = clclm.getCommonLibClassLoader("jiopi-main-log4j-1.2.16.jar");
		CommonLibClassLoader clcl2 = clclm.getCommonLibClassLoader("jiopi-main-commons-logging-1.1.1.jar");
		assertNotNull(clcl);
		assertSame(clcl,clcl2);
		try {
			ArrayList<String> commonJars = new ArrayList<String>();
			commonJars.add("jiopi-main-commons-logging-1.1.1.jar");
			commonJars.add("jiopi-main-log4j-1.2.16.jar");
			Class<?> c = clcl.loadClass("org.apache.log4j.Logger",commonJars);
			assertNotNull(c);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
}
